package cn.edu.zafu.bigdata.hdb;
import java.util.List;
import java.util.Arrays;
class GenericUtils {

    // 泛型方法，找到列表中的最大值
    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            throw new IllegalArgumentException("List cannot be null or empty");
        }

        T max = list.get(0);
        for (T element : list) {
            if (element.compareTo(max) > 0) {
                max = element;
            }
        }
        return max;
    }
}
public class TestGenericUtils {
    public static void main(String[] args) {
        // 创建一个整数列表
        List<Integer> intList = Arrays.asList(3, 5, 7, 2, 8, 1);
        Integer maxInt = GenericUtils.findMax(intList);
        System.out.println("Maximum integer: " + maxInt); // 输出：Maximum integer: 8

        // 创建一个字符串列表
        List<String> strList = Arrays.asList("apple", "banana", "pear", "orange");
        String maxStr = GenericUtils.findMax(strList);
        System.out.println("Maximum string: " + maxStr); // 输出：Maximum string: pear
    }
}
